#ifndef _MY_QUEUE_H_
#define _MY_QUEUE_H_
#include <stdio.h>
#include <stdint.h> // 包含 uint16_t 类型

#define RECV_BUFF_SIZE 32768
#define RECV_ITEM_CNT 40


// 定义 WAV 文件头结构体
/* sizeof(WAV_FMT) = 12 */
typedef struct WAV_RIFF 
{
    char ChunkID[4]; /* "RIFF" */
    uint32_t ChunkSize; /* 从下一个地址开始到文件末尾的总字节数 */
    char Format[4]; /* "WAVE" */
} __attribute__ ((packed)) RIFF_t;

/* sizeof(WAV_FMT) = 24 */
typedef struct WAV_FMT 
{
    char Subchunk1ID[4]; /* "fmt " */
    uint32_t Subchunk1Size; /* 16 for PCM */
    uint16_t AudioFormat; /* PCM = 1*/
    uint16_t NumChannels; /* Mono = 1, Stereo = 2, etc. */
    uint32_t SampleRate; /* 8000, 44100, etc. */
    uint32_t ByteRate; /* = SampleRate * NumChannels * BitsPerSample/8 */
    uint16_t BlockAlign; /* = NumChannels * BitsPerSample/8 */
    uint16_t BitsPerSample; /* 8bits, 16bits, etc. */
} __attribute__ ((packed)) FMT_t;

typedef struct WAV_DATA 
{
    char Subchunk2ID[4]; /* "data" */
    uint32_t Subchunk2Size; /* data size */
} __attribute__ ((packed)) DATA_t;


typedef struct WavHeaderSt
{
    RIFF_t wavRiffSt;
    FMT_t  wavFmtSt;
    WAV_DATA wavDataSt;
} WavHeader;

typedef struct AudioRecvItem
{
    int buffLen;
    char buff[RECV_BUFF_SIZE];
}AudioRecvItemSt;

// Queue 利用数组,制作循环队列
#define QUEUE_MAXSIZE 20

typedef struct queueStruct
{
    int maxSize;
    int count;
    int front;
    int rear;
    AudioRecvItemSt array[QUEUE_MAXSIZE];
}QUEUE_STU;

typedef struct AudioRecvAll
{
    bool bIsReceiving;
    WavHeader wavHeaderObj;
    QUEUE_STU recvList;
}AudioRecvAllSt;

int InsQueue(QUEUE_STU *arg, AudioRecvItemSt value);
int PopQueue(QUEUE_STU *arg, AudioRecvItemSt *value);
int InitQueue(QUEUE_STU *arg);
int DestroyQueue(QUEUE_STU *arg);
bool IsQueueEmpty(QUEUE_STU *queue);


#endif